<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>发票</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
	.commentinfo{ width:100%;margin-top:5px;padding:0 10px 10px 10px;background: #FFF;box-sizing:border-box;}
	.commentinfo *{box-sizing:border-box;}
	.commentinfo .item{display:flex;flex-direction:column;width:100%;padding:20px 0;border-bottom:1px dashed #ededed;}
	.commentinfo .item:last-child{ border-bottom: 0;}
	.commentinfo .item .t1{width:100%;color:#333;padding:10px 0}
	.commentinfo .item .t2{width:100%;color:#888;padding-left:20px}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">发票</div>
          <div class="layui-card-body" pad15>
						<div class="layui-col-md4" style="padding-bottom:10px">
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="datadel(0)">删除</button>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="setst(0,1)">已审</button>
							<button class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="setst(0,0)">未审</button>
						</div>
						<div class="layui-form layui-col-md8" style="text-align:right;padding-bottom:10px">
							<div class="layui-inline layuiadmin-input-useradmin">
								<label class="layui-form-label" style="width:60px">订单号</label>
								<div class="layui-input-block" style="width:180px;margin-left:90px">
									<input type="text" name="ordernum" autocomplete="off" class="layui-input" value="">
								</div>
							</div>
							<div class="layui-inline layuiadmin-input-useradmin">
								<label class="layui-form-label" style="width:60px">抬头</label>
								<div class="layui-input-block" style="width:120px;margin-left:90px">
									<input type="text" name="invoice_name" autocomplete="off" class="layui-input" value="">
								</div>
							</div>
							
							<div class="layui-inline">
								<label class="layui-form-label" style="width:60px;">时间</label>
								<div class="layui-input-block" style="width:180px;margin-left:90px">
									<input type="text" name="ctime" id="ctime" autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
								</button>
							</div>
						</div>
						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: '{$Request.url}' //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
			{type:"checkbox"},
      {field: 'id', title: 'ID',  width:60},
      {field: 'ordernum', title: '订单号',width:260,templet:function (d){
      	if(d.order_type == 'shop') {
			var url = '{:url('ShopOrder/index')}/ordernum/'+d.ordernum+'/isopen/1';
			var typeName = '普通';
		}
      	else if(d.order_type == 'collage') {
			var url = '{:url('CollageOrder/index')}/ordernum/'+d.ordernum+'/isopen/1';
			var typeName = '拼团';
		}
	  	else if(d.order_type == 'seckill') {
			var url = '{:url('SeckillOrder/index')}/ordernum/'+d.ordernum+'/isopen/1';
			var typeName = '秒杀';
		}
      	return '<div>['+typeName+'] <a href="javascript:void(0)" style="color:deepskyblue" onclick="openmax(\''+url+'\')">'+d.ordernum+'</a></div>'}},
      {field: 'type', title: '发票类型',templet: function (d){return d.type == 1 ? '普票' : '增值税专票'},width:150},
      {field: 'name_type', title: '抬头类型',width:80,sort: true,templet:function (d){return d.name_type == 1 ? '个人' : '公司'}},
		  {field: 'invoice_name', title: '抬头'},
		  {field: 'tax_no', title: '税号'},
		  {field: 'address', title: '注册地址和电话',templet:function (d){return '<div>'+d.address+'</div><div>'+d.tel+'</div>'}},
		  {field: 'bank_name', title: '银行和账号',templet:function (d){return '<div>'+d.bank_name+'</div><div>'+d.bank_account+'</div>'}},
		  {field: 'mobile', title: '手机和邮箱',templet:function (d){return '<div>'+d.mobile+'</div><div>'+d.email+'</div>'}},
      {field: 'create_time', title: '时间',sort: true,templet:function(d){ return date('Y-m-d H:i',d.create_time)},width:150},
      {field: 'status', title: '状态',templet:function(d){ return d.status==1?'<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="setst('+d.id+',0)">已审核</button>':'<button class="layui-btn layui-btn-sm layui-btn-danger" onclick="setst('+d.id+',1)">未审核</button>'},width:80},
      {field: 'operation', title: '操作',templet: '<div><button class="table-btn" onclick="toreply({{d.id}})">回复</button><button class="table-btn" onclick="datadel({{d.id}})">删除</button></div>',width:200}
    ]]
  });

  //日期范围选择
  layui.laydate.render({
	  elem: '#ctime',
	  trigger: 'click',
	  range: '~' //或 range: '~' 来自定义分割字符
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
	//审核状态
	function setst(id,st){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			var ids = [];
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id)
		}
		layer.confirm('确定要改为'+(st==0?'未审核':'已审核')+'吗?',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('setst')}",{ids:ids,st:st},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	//删除
	function datadel(id){
		var ids = [];
		if(id==0){
			var checkStatus = table.checkStatus('tabledata')
			var checkData = checkStatus.data; //得到选中的数据
			if(checkData.length === 0){
				 return layer.msg('请选择数据');
			}
			var ids = [];
			for(var i=0;i<checkData.length;i++){
				ids.push(checkData[i]['id']);
			}
		}else{
			ids.push(id)
		}
		layer.confirm('确定要删除吗?',{icon: 7, title:'操作确认'}, function(index){
			//do something
			layer.close(index);
			var index = layer.load();
			$.post("{:url('del')}",{ids:ids},function(data){
				layer.close(index);
				dialog(data.msg,data.status);
				tableIns.reload()
			})
		});
	}
	function toreply(id){
		layui.laytpl(replytpl.innerHTML).render({}, function(html){
				var toreplyLayer = layer.open({type:1,title:'回复',content:html,shadeClose:true,btn:['确定','取消'],yes:function(){
					var index = layer.load();
					$.post("{:url('reply')}",{id:id,content:$('#replycontent').val()},function(data){
						layer.close(index);
						layer.close(toreplyLayer);
						dialog(data.msg,data.status);
					})
				}});
			});
	}
	</script>
<script id="replytpl" type="text/html">
	<div class="layui-form-item" style="margin-top:40px;margin-right:20px;">
		<label class="layui-form-label" style="width:40px">回复内容</label>
		<div class="layui-input-inline" style="width:250px">
			<textarea type="text" id="replycontent" class="layui-textarea"></textarea>
		</div>
	</div>
</script>

<script>
function previewImg(url){
	layer.open({type:1,area:'500px',content:'<div style="margin:auto auto;text-align:center"><img src="'+url+'" style="max-width:100%;max-height:100%"/></div>',title:false,shadeClose:true})
}
</script>
	{include file="public/copyright"/}
</body>
</html>